package main

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"net/http"
)

const (
	COOKIE_NAME = "DonHz"
)

func main() {
	r:=gin.Default()
	r.LoadHTMLFiles("login.html","account.html", "manage.html")
	r.GET("/login", func(ctx *gin.Context) {
		ctx.HTML(200, "login.html", nil)
	})
	r.GET("/login/body", Login)
	r.GET("/account", func(ctx *gin.Context) {
		ctx.HTML(200, "account.html", nil)
	})
	r.GET("/account/body", Auth, Account)
	r.GET("/manage", func(ctx *gin.Context) {
		ctx.HTML(200, "manage.html", nil)
	})
	r.GET("/manage/body", Auth, Manage)
	r.Run("localhost:5678")
}

func Login(ctx *gin.Context) {
	uid:="1"
	payload:=JWTPayload{UserDefined: map[string]any{"uid": uid}}
	token, _:=GenJWT(DefaultHeader, payload, JWT_SECRET)
	fmt.Println("jwtx token: ", token)
	ctx.JSON(200, gin.H {
		"uid": uid,
		"jwtx": token,
	})
}

func Manage(ctx *gin.Context) {
	ctx.JSON(http.StatusOK, gin.H{
		"uid": ctx.GetString("uid"),
	})
}

func Account(ctx *gin.Context) {
	ctx.JSON(http.StatusOK, gin.H{
		"uid": ctx.GetString("uid"),
	})
}

